package com.tony.study.designMode.DM1_工厂方法;

import com.tony.study.designMode.DM1_工厂方法.DM1.Chat;
import com.tony.study.designMode.DM1_工厂方法.Factory.ChatFactory1;
import com.tony.study.designMode.DM1_工厂方法.Factory.ChatFactory2;
import com.tony.study.designMode.DM1_工厂方法.Factory.ChatFactory3;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: FactoryTest
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/01/13:32
 * @Description: 工厂模式测试
 * (对比发现，静态工厂模式最佳，省去了工厂实例的创建)
 */
public class FactoryTest {

    public static void main(String[] args) {
        //1、使用单方法工厂模式进行测试
        ChatFactory1 chatFactory1 = new ChatFactory1();
        String num = "1";

        Chat wechat1 = chatFactory1.createChat("WeChat");
        wechat1.chatting(num);

        Chat qq1 = chatFactory1.createChat("QQ");
        qq1.chatting(num);

        Chat douyin = chatFactory1.createChat("DouYin");
        if (douyin == null) {
            System.out.println("创建抖音聊天工具实例失败！");
        } else {
            douyin.chatting(num);
        }

        System.out.println("======分割线======");

        //2、使用多方法工厂模式进行测试
        ChatFactory2 chatFactory2 = new ChatFactory2();
        num = "2";

        Chat wechat2 = chatFactory2.createWeChat();
        wechat2.chatting(num);

        Chat qq2 = chatFactory2.createQQChat();
        qq2.chatting(num);

        System.out.println("======分割线======");

        //3、使用静态工厂模式进行测试
        num = "3";

        Chat wechat3 = ChatFactory3.createWeChat();
        wechat3.chatting(num);

        Chat qq3 = ChatFactory3.createQQChat();
        qq3.chatting(num);

    }
}
